<template>
  <div class="category-main">
    <div class="tab-bars">
      <van-tabs v-model="categoryId" @click="changNav" sticky>
  <van-tab  v-for="item in navData" :key="item.id" :title="item.name" :name="item.id">
    
  </van-tab>
</van-tabs>
    </div>
  <div class="goods-list">
    <div class="header">
     <div class="title">{{currentNav.name}}</div>
     <div class="desc">{{currentNav.front_desc}}</div>
    </div>
     <div class="list">
      <div class="item" v-for="item in goodsList" :key="item.id">
          <img :src="item.list_pic_url" alt="">
          <div class="name">{{item.name}}</div>
          <div class="price">￥{{item.retail_price}}</div>
      </div>
      </div>
  </div>
  </div>
</template>

<script>
import divceApi from "@/netapi/divce/divice.js"
export default {
  name: "HomeCategory",
  components: {

  },
  data () {
    return {
      categoryId:"",
      navData:[],
      currentNav:[],
      goodsList:[]
    };
  },
  computed: {

  },
  created () {
    this.categoryId = this.$route.params.id;
    this.getNabData()
    this.getGoodsList()
  },
  mounted () {

  },
  methods: {
    getNabData () {
      divceApi.cateGory({
        id:this.categoryId
      })
      .then(res=>{
        this.navData = res.navData;
        
      })
    },
    getGoodsList(){
      divceApi.goodList({
               categoryId:this.categoryId
      })
      .then(res=>{
        this.goodsList = res.data;
        this.currentNav = res.currentNav;
      })
    },
    changNav(val){
    this.categoryId = val;
    this.getGoodsList()
    }
  },
};
</script>

<style scoped lang="scss">
.category-main {
  width: 100%;
  .tab-bars{
    margin-top: 46px;
    border-bottom: 8px solid #F4F4F4;
  }
  .goods-list{
    width: 100%;
    .header{
      height: 100px;
      text-align: center;
      border-bottom: 1Px solid #F4F4F4;
      .title{
        font-size: 14px;
        font-weight: bold;
        margin-top: 32px;
        margin-bottom: 16px;
      }
      .desc{
        font-size: 12px;
        color: #ACAAAC;
      }
    }
    .list{
      display: flex;
      justify-content: space-between;
      background-color:  #F4F4F4;
      flex-wrap: wrap;
      .item{
        background-color: #fff;
        text-align: center;
        width: 186px;
        height: 239px;
        margin-bottom: 3px;
        img{
          width: 100%;
          height: 164px;
        }
        .name{
          color: black;
          margin-bottom: 20px;
        }
        .price{
          color: red;
        }
      }
    }

  }
}
</style>
